﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Customer_Profile.Admin
{
    public partial class MenuModify : System.Web.UI.Page
    {
        protected static int MenuId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                    MenuId = Convert.ToInt32(Request.QueryString["ID"].ToString());
                else
                {
                    KVB.Common.JavaScript.ViewMsgGoUrl("MenuManage.aspx", "You Must Select！");
                }
                if (MenuId != -1)
                {
                    DataSet ds = MenuDao.getMenuInfo(MenuId);
                    txtName.Value = ds.Tables[0].Rows[0]["Menu_name"].ToString();
                    txtRemark.Value = ds.Tables[0].Rows[0]["Remark"].ToString();
                    txtUrl.Value = ds.Tables[0].Rows[0]["URL"].ToString();
                    txtOrderid.Value = ds.Tables[0].Rows[0]["Order_id"].ToString();
                    if (ds.Tables[0].Rows[0]["USED"].ToString() == "Y")
                        drpUsed.SelectedIndex = 0;
                    else
                        drpUsed.SelectedIndex = 1;
                    txtHelp.Value = ds.Tables[0].Rows[0]["Help_URL"].ToString();

                    if (ds.Tables[0].Rows[0]["Help_YN"].ToString() == "Y")
                        drpHelpUse.SelectedIndex = 0;
                    else
                        drpHelpUse.SelectedIndex = 1;

                    if (ds.Tables[0].Rows[0]["Action_Mode"].ToString() == "0")
                        drpOpen.SelectedIndex = 0;
                    else
                        drpOpen.SelectedIndex = 1;
                }
            }
        }

        protected void ibtnModify_ServerClick(object sender, EventArgs e)
        {
            MenuInfoEntity menuCon = new MenuInfoEntity();
            menuCon.MenuId = MenuId.ToString();
            menuCon.MenuName = txtName.Value;
            menuCon.Mark = txtRemark.Value;
            menuCon.Url = txtUrl.Value;
            menuCon.Orderid = txtOrderid.Value;
            menuCon.OpenMode = drpOpen.SelectedValue.ToString();
            menuCon.Used = drpUsed.SelectedValue.ToString();
            menuCon.HelpUrl = txtHelp.Value;
            menuCon.HelpYn = drpHelpUse.SelectedValue.ToString();

            Hashtable htMenuInfo = new Hashtable();
            htMenuInfo.Add("MenuInfo", menuCon);

            try
            {
                bool isSucess = MenuDao.updateMenuInfo(htMenuInfo);
                if (isSucess == true)
                {
                    Response.Write("<script language=javascript>alert('Succeed!');</script>");

                    //记录用户操作日志
                    //CVOC.Comm.WriteSystemLog(Session["SS_USER_ID"].ToString(), Utility.ReplaceChar(Utility.ReplaceQuote(Request["menu_idx"].ToString()), true), "03", Page.Request.UserHostAddress, Page.Request.Path, "菜单修改操作，修改后的菜单名称为：" + txtName.Value);
                }
            }
            catch
            {
                Response.Write("<script language=javascript>alert('Error!');</script>");
            }
        }

        protected void ibtnBack_ServerClick(object sender, EventArgs e)
        {
            Response.Redirect("MenuManage.aspx", true);
        }
    }
}
